Tim_ATmega328p.h

					
/*************************************************
 * Timers setting - counting, interrupts, other timer tasks
 * This Library files are not in finished state and very experimental 
 *************************************************/

#ifndef _TIM_ATmega328p_H_
#define _TIM_ATmega328p_H_

#include <xc.h>
#include "main.h"

/*  Enumeration of Timers for simplifying access 
 */
typedef enum
{
  TIM0 = 0x00,
  TIM1 = 0x01,
  TIM2 = 0x02
} tim_t;

/*  Modes of Timer work
 */
typedef enum
{
  OUT_COMP_A = 0x00,      // Interruption after Timer/Counter Overflow Event
  ADC_TRIGGERING = 0x01,    // ADC Measurement after each capture-compare event  (to be implemented)
  PWM = 0x02,               // Normal PWM (Not used yet, changes are possible)
  TIM2_A_SOUND_PWM = 0x03     // Phase Correct PWM
} tim_mode_t;

/***************************** FUNCTION PROTOTYPES *****************************/

my_bool TIMER_Set(tim_t Timer, tim_mode_t Mode, unsigned long Period_us);
void TIM1_Set_PWM(uint8_t Duty_PWM);
uint16_t set_TIM2_prescaler(unsigned long Period_us, tim_mode_t Mode);

#endif // _TIM_ATmega328p_H_